package br.com.tcc.systemdx.persistence.hibernate;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.tcc.systemdx.domain.OcorrenciaDoenca;
import br.com.tcc.systemdx.persistence.OcorrenciaDoencaDAO;

@Repository(OcorrenciaDoencaDAO.BEAN_NAME)
@Transactional
public class OcorrenciaDoencaHibernateDAOImpl 
				extends AbstractEntityHibernateDAOImpl<OcorrenciaDoenca> 
				implements OcorrenciaDoencaDAO {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7259656018826615832L;

	public int countByMonthYear(int month, int year, String cid) {
		
		List<OcorrenciaDoenca> ocorrencias = new ArrayList<OcorrenciaDoenca>();
		Calendar calendar = Calendar.getInstance();
		
		calendar.set(year, month, 1, 0, 0, 0);
		
		Date data = calendar.getTime();
		if(cid.equalsIgnoreCase("todos") || cid.equalsIgnoreCase("all") ||
					cid.equalsIgnoreCase("todas")) {
			ocorrencias = findByCriteria(Restrictions.eq("data_ocorrencia", data));
		} else {
			ocorrencias = findByCriteria(Restrictions.and(Restrictions.eq("CID", cid), 
					Restrictions.eq("data_ocorrencia", data)));
		}
		
		return ocorrencias.size();
	}
	
	
	

}
